package com.inspur_video.inspur_video.controller;

import com.inspur_video.inspur_video.bean.Response;
import com.inspur_video.inspur_video.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 小浩
 * @date 2018-07-25 17:24
 * @package com.inspur_video.inspur_video.controller
 * @description 收藏控制器
 */
@RestController
@RequestMapping("/favorite")
public class FavoriteController {
    @Autowired
    HttpSession httpSession;
    @Autowired
    FavoriteService favoriteService;

    @RequestMapping("/add/{uid}/{aid}")
    public Response addFavorite(@PathVariable("uid") int uid, @PathVariable("aid") String aid) {
//        int uid=Integer.parseInt(httpSession.getAttribute("user").toString());
        boolean flag = favoriteService.addFavorite(uid, aid);
        if (flag) {
            return new Response(200, "");
        } else {
            return new Response(500, "");
        }
    }

    @RequestMapping("/delete/{uid}/{vid}")
    public Response deleteFavorite(@PathVariable("uid") int uid, @PathVariable("vid") String aid) {
//        int uid=Integer.parseInt(httpSession.getAttribute("user").toString());
        return favoriteService.deleteFavorite(uid,
                aid) ? new Response(200, "") : new Response(500, "");
    }

    @RequestMapping("/get/{uid}")
    public List getFavorite(@PathVariable("uid") int uid) {
//        int uid=Integer.parseInt(httpSession.getAttribute("user").toString());
        return favoriteService.getFavorite(uid);
    }

}
